#ifndef KMYIFILE_H
#define KMYIFILE_H

#include <string>
#include <map>
using namespace std;
//#include "KmyTypedef.h"
#include "KmyImagePak.h"
#include "KmySpriteTemplate.h"
#include "ScriptRunner/KmyScript.h"
#include "KmyFont.h"

#include "ResPath/ResPathImage.h"
#include "ResPath/ResPathScript.h"
#include "ResPath/ResPathSound.h"
#include "ResPath/ResPathSprite.h"
#include "ResPath/ResPathFont.h"

class KmyIFile
{
public:
    KmyIFile();
    KmyIFile(const string &root_path);
    virtual ~KmyIFile();

    const string rootpath;

//    static const int FILEMODE_READ      = 0;    //"r"
//    static const int FILEMODE_WRITE     = 1;    //"w"
//    static const int FILEMODE_APPEND    = 2;    //"a"   打开文件并移动到末尾（不支持跳转
//    static const int FILEMODE_READ_P    = 3;    //"r+"  读写（文件必须存在
//    static const int FILEMODE_WRITE_P   = 4;    //"w+"  读写（文件不存在则新建
//    static const int FILEMODE_APPEND_P  = 5;    //"a+"  打开文件并移动到末尾（可读，支持跳转（写入时自动跳到末尾

    static const int FILE_OPEN_RESULT_SUCCESS = 0;
    static const int FILE_OPEN_RESULT_FAIL = 1;
    static const int FILE_OPEN_RESULT_ALREADY = 2;

    virtual int fileOpen(string &filename) = 0;
    virtual void fileClose(string &filename) = 0;
    virtual int read(const string &filename, void* buff, int size) = 0;
    virtual int getFileSize(const string &filename) = 0;
//    virtual string readLine(const string &filename) = 0;
//    virtual string readString(const string &filename) = 0;
//    virtual string readLine(void *src, int &size) = 0;
//    virtual string readString(void *src, int &size) = 0;
//    virtual int readInt(const string &filename) = 0;
//    virtuaKmyImagePakeadShort(const string &filename) = 0;
//    virtual char readChar(const string &filename) = 0;
    KmyImagePak* readImagePak(ResPathImage *rpi);
    KmyScript* readScript(ResPathScript *rps);
    KmySpriteTemplate* readSprite(ResPathSprite *rps);
    KmyFont* readFont(ResPathFont *rpf);

// 删除，平台无关
//    /** 创建纹理buff（平台相关，平台相关暂时用文件管理器管） */
//    virtual KmyITexture *createTexture(const string &name, int mode, const u8* data,
//                               int w, int h, bool is_buffer) = 0;
//private:
//    map<string, FILE*> file_cache;
};

#endif // KMYIFILE_H
